"use client";
import { redirect, useRouter } from "next/navigation";
import { useEffect } from "react";
import { initSysDict } from "@/app/gloableTools";

export default function RootPage() {
  const router = useRouter();



  useEffect(() => {
    const init = async () => {
      const token = localStorage?.getItem("token");
      const user_type = localStorage?.getItem("user_type");
      const user = JSON.parse(localStorage?.getItem("sys_user") || "{}");

      const isLogin = !!token;
      
      if (!isLogin) {
        router.push(`/login`);
      } else {
        await initSysDict();
        
        if (user_type === "01") {
          router.push(`/agent/main/home`);
        } else if (user_type === "00") {
          router.push(`/agent/system/home`);
        }
      }
    };
    init();
  }, []);

  return null;
}
